package servlet;

import bean.AdminBean;
import util.JdbcUtil;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class HomepageServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int id=Integer.parseInt(req.getParameter("id"));
        String sql="SELECT * FROM admin where aid=?";
        try {
            PreparedStatement ps = JdbcUtil.getConnection().prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
            ps.setInt(1,id);
            ResultSet rs = ps.executeQuery();
            rs.absolute(1);
            ArrayList<AdminBean> arr=new ArrayList<AdminBean>();
            AdminBean ab=new AdminBean();
            ab.setAid(rs.getInt(1));
            ab.setName(rs.getString(2));
            ab.setSex(rs.getString(3));
            ab.setAge(rs.getInt(4));
            ab.setTel(rs.getString(5));
            ab.setAddress(rs.getString(6));
            ab.setWid(rs.getInt(7));
            System.out.println(arr.toString());
            HttpSession session=req.getSession();
            session.setAttribute("ab", ab);
            resp.sendRedirect("menu.jsp");
        } catch (SQLException ex) {
            ex.printStackTrace();
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }


    }
}
